<template >
    <rx-dialog @handOk="okFun" @cancel="closeWindow" :oktext="i18n('taskCheck.btnAssign','提交')" order="buttom" btnalign="center">
        <rx-fit>
            <div style="height:100%;width:100%;padding:5px;">
                <template>
                    <div>
                        <a-checkbox
                            v-model:checked="commuState.checkAll"
                            :indeterminate="commuState.indeterminate"
                            @change="onCheckAllChange"
                        >
                            {{i18n('taskExecutors.checkAll','全选')}}
                        </a-checkbox>
                    </div>
                    <a-divider />
                    <a-checkbox-group :options="plainOptions" @change="selectChange"  v-model="commuState.checkedList"></a-checkbox-group>
                </template>
            </div>
        </rx-fit>
    </rx-dialog>
</template>

<script>
import {RxDialog, Util, RxFit} from '@lowcode/jpaas-common-lib'
import userState from "@/assets/js/userState";

export default {
    name: "withdraw-tips",
    mixins: [userState],
    omponents: {
        RxFit,
        RxDialog,
    },
    props: {
        commu: {type: Object, required: false},
        layerid: String,
        lydata: Object,
        destroy: {
            type: Function
        }
    },
    data() {
        return {
            selectItem:{},
            plainOptions:[],
            commuState:{
                indeterminate: true,
                checkAll: false,
                checkedList: [],
            }
        }
    },
    created() {
        this.initCommuData();
    },
    methods: {
        onCheckAllChange(e){
            Object.assign(this.commuState, {
                checkedList: [],
                indeterminate: false,
            });
            if(this.commuState.checkAll){
                this.plainOptions.forEach(receiver=>{
                    this.commuState.checkedList.push(receiver.value);
                });
            }
        },
        initCommuData(){
            this.commu.receivers.forEach(receiver=>{
                if(1!=receiver.readed){
                    this.plainOptions.push({label:receiver.receiverName, value:receiver.id});
                }
            });
        },
        //多选变化
        selectChange(ary){
            if(ary.length==this.plainOptions.length){
                this.commuState.checkAll=true;
            }else {
                this.commuState.checkAll=false;
            }
        },
        okFun(btn){
            if(this.commuState.checkedList.length==0){
                btn.loading = false;
                this.$message.error(this.i18n("msa.selectUserTips","请勾选需要撤销的用户！"));
                return;
            }
            let all=false;
            if(this.commuState.checkAll && this.commu.receivers.length==this.commuState.checkedList.length){
                all=true;
            }
            let returnData={
                all:all,
                receiverIds:this.commuState.checkedList[0]
            }

            for(let i=1;i<this.commuState.checkedList.length;i++){
                returnData.receiverIds+=","+this.commuState.checkedList[i];
            }

            Util.closeWindow(this, "ok",returnData);
        },
        closeWindow(){
            Util.closeWindow(this, "cancel");
        },
        i18n(name,text,key){
            return this.$ti18(name,text,"bpmTask",key);
        },
    },
}
</script>

<style scoped lang="less">

</style>
